import java.util.Iterator;


class FibIterator implements Iterable<Integer>, Iterator<Integer> {

    private int prev1;
    private int prev2;

    FibIterator(int prev1, int prev2)
    {
        this.prev1 = prev1;
        this.prev2 = prev2;
    }

    FibIterator()
    {
        this(1, 0);
    }

    public Iterator<Integer> iterator()
    {
        return this;
    }

    public boolean hasNext()
    {
        return true;
    }

    public Integer next()
    {
        int original_prev2 = prev2;
        int fib = prev1 + prev2;
        prev2 = prev1;
        prev1 = fib;

        return original_prev2;
    }

    public void remove() throws UnsupportedOperationException
    {
        throw new UnsupportedOperationException();
    }
}


public class fibonacci {

    public static void main(String[] argv) throws UnsupportedOperationException
    {
        int fib_count = Integer.valueOf(argv[0]) + 1;
        Iterable<Integer> fib_iter = new FibIterator();

        // Normal 'for' loop might be better, but this shows foreach.
        for (Integer fib : fib_iter) {
            if (fib_count < 1) {
                break;
            }
            else {
                fib_count -= 1;
            }
            System.out.print(fib + " ");
        }
        System.out.println("...");
    }
}
